/*
 * @Author: your name
 * @Date: 2022-02-04 13:06:01
 * @LastEditTime: 2022-02-04 13:35:55
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \ts\ts-images\04接口.ts
 */
// 普通接口
interface iter4 {
  name: string;
  age: number;
  say(): string; //接口方法， 返回值string
  sayH(): void; // 不需要返回值
}
let i1: iter4 = {
  name: "变量",
  age: 23,
  say: () => {
    return "2";
  },
  sayH: () => {},
};

function getObj(obj: iter4) {
  console.log(obj.name + obj.age);
}

getObj({
  name: "函数传参",
  age: 23,
  say: () => {
    return "2";
  },
  sayH: () => {},
});

// 接口非必穿参数 ?:
interface iter41 {
  name: string;
  age: number;
  width?: number; // 可填可不填
}

let i2: iter41 = { name: "d", age: 23 };

// 任意值属性
interface iter43 {
  name: string;
  [proname: string]: any; // 属性是字符串，值随意
}
let i3: iter43 = { name: "2", df: "df" };

interface pp1 {
  name: string;
}

interface pp2 {
  name: string;
  age: number;
}

let a100: pp2 = { name: "22", age: 1 };
let a1001: pp1 = a100; // 属性多个赋值给属性少的内问题
// let a1001:pp1= {name:'22',age :1} // 这样不行

console.log(a1001);

// / 接口与数组
// 我们定义了StringArray接口，它具有索引签名。
// 这个索引签名表示了当用 number去索引StringArray时会得到string类型的返回值
interface IStringArray {
  [index: number]: string;
}

let myArray: IStringArray;
myArray = ["邱淑贞", "赵今麦"];

let myStr: string = myArray[1];
console.log(myStr);
